package flextv.data {

import flash.data.SQLResult;
import flash.errors.SQLError;
import flash.net.Responder;

import flextv.core.logic.Util;
import flextv.core.vo.StoredItem;

import mx.collections.ArrayCollection;

internal class StoredItemResponder extends Responder {
	
	private var storedItems: ArrayCollection;
	
	public function StoredItemResponder() {
		super(buildPlaylistsResult, logError);
	}
	
	
	public function buildPlaylistsResult(result: SQLResult): void{
		this.storedItems = new ArrayCollection();
 
		if(result != null && result.data != null) {
			for(var i: int = 0; i < result.data.length; i++) {
				const item: StoredItem = StoredItem(result.data[i]);
				
				// compute data
				item.thumbnailUrl = "file://" + Util.resolveThumbFile(item).nativePath;
				
				this.storedItems.addItem(item);
			}
		}
	}
 
	public function logError(error: SQLError):void{
		throw new Error(error.toString());
	}		
 
	public function getStoredItems(): ArrayCollection {
		return this.storedItems;
	}
	
}
}